@extends('layouts.app')
@include('good.sidebar')
@section('content')
    @php
        use Illuminate\Support\Facades\Auth;
        use App\Modules\User\Models\Admin;
        $authUser = Auth::user();
    @endphp
    <div class="content">

        <div class="row custom-invoice">
            {{--            <p>{{ $good->name }}</p>--}}
            <br/>
            <br/>
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th width="10px"></th>
                    <th style="min-width:80px">用户</th>
                    <th style="min-width:50px">头像</th>
                    <th style="min-width:250px">评论内容</th>
                    <th style="min-width:80px">时间</th>
                    <th style="min-width:50px">显示</th>
                    <th style="min-width:100px">敏感内容检测</th>
                    <th style="min-width:100px">评论时间</th>
                    <th style="min-width:100px">系统回复内容</th>
                    <th style="min-width:90px">系统回复者</th>
                    <th style="min-width:90px">商家回复者</th>
                    <th style="min-width:300px">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($comment as $item)
                    <tr>
                        <td class="view_comment" onclick="viewComment(this, {{$item->id}})">
                            @if (isset($item->child) && $item->child)
                                <i class='fa fa-angle-down'></i>
                            @endif
                        </td>
                        <td>
                            @php
                                echo empty($user->get($item->user_id)) ?  '商家回复':$user->get($item->user_id)->nickname
                            @endphp
                        </td>
                        <td>
                            @php
                                echo empty($user->get($item->user_id)) ?  '':"<img src=".$user->get($item->user_id)->avatar." width='30'/>";
                            @endphp
                        </td>
                        <td>
                            <a href="{{ route('admin.order.good_index', ['order_id' => $item->order_id]) }}">{{ $item->content }}</a>
                        </td>
                        <td>{{$item->created_at}}</td>
                        <td>{!! $item->is_show? "<i class='fa fa-check'></i>":"" !!}</td>
                        <td>{!! $item->is_checked? "<i class='fa fa-check'></i>":"" !!}</td>
                        <td>{{ $item->created_at }}</td>
                        <td>{{ $item->system_reply }}</td>
                        <td>{{ $item->system_responder }}</td>
                        <td>
                            @if (isset($item->child) && $item->child)
                                {{ $item->child->merchant_reply_username }}
                            @endif
                        </td>
                        <td>
                            {{-- 商家回复 --}}
                            @if(!$item->merchant_reply_username)
                                @if($authUser->is_merchant_staff == Admin::MERCHANT_AUTH)
                                    @can('merchant_staff_and_package_comment_reply')
                                        <a class="btn btn-primary btn-xs merchantReply" data-pid="{{$item->id}}"
                                           data-url="{{ route('admin.comment.merchantReply', ['id' => $item->id]) }}"><i
                                                class="fa fa-user"></i> 商家回复</a>
                                    @endcan
                                @endif
                            @else
                                @if($authUser->is_merchant_staff == Admin::MERCHANT_AUTH)
                                    @can('merchant_staff_and_package_comment_del')
                                        <a class="btn btn-primary btn-xs" data-pid="{{$item->id}}"
                                           href="{{ route('admin.comment.merchantDel', ['id' => $item->id]) }}"><i
                                                class="fa fa-user"></i> 删除商家回复</a>
                                    @endcan
                                @endif
                            @endif

                            {{-- 系统回复 --}}
                            @can("comment-system")
                                @if($item->system_reply)
                                    <a class="btn btn-primary btn-xs examine"
                                       data-url="{{ route('admin.comment.reply', ['id' => $item->id]) }}"
                                       data-system-reply="{{$item->system_reply}}"><i class="fa fa-user"></i> 修改内容</a>
                                @else
                                    <a class="btn btn-primary btn-xs examine"
                                       data-url="{{ route('admin.comment.reply', ['id' => $item->id]) }}"
                                       data-system-reply="{{$item->system_reply}}"><i class="fa fa-user"></i> 系统回复</a>
                                @endif
                            @endcan

                            @if(!empty($item->image))
                                <a class="btn btn-info btn-xs showHideForm" data-image="{{ $item->image }}"><i
                                        class="fa fa-file-image-o"></i> 查看图片</a>
                            @endif
                            @can("comment-delete")
                                <a class="btn btn-danger btn-xs delete-confirm"
                                   data-href="{{ route('admin.comment.destroy', ['id' => $item->id]) }}"><i
                                        class="fa fa-trash-o"></i> 删除</a>
                            @endcan
                            @can('comment-edit')

                                @if($item->is_show == 1)
                                    <a class="btn btn-primary btn-xs"
                                       href="{{ route('admin.good.comment.hide', ['id' => $item->id,'is_show'=>0]) }}"><i
                                            class="fa fa-ban"></i> 隐藏</a>
                                @else
                                    <a class="btn btn-primary btn-xs"
                                       href="{{ route('admin.good.comment.hide', ['id' => $item->id,"is_show"=>1]) }}"><i
                                            class="fa fa-ban"></i> 显示</a>
                                @endif
                            @endcan

                            <a class="btn btn-success btn-xs"
                               href="{{ route('admin.good.index', ['id' => $item->link_id, 'shop_id' => $shopId]) }}"><i
                                    class="fa fa-comment-o"></i> 商品</a>
                        </td>
                    </tr>
                    @if (isset($item->child) && $item->child)
                        <tr id='reply_comment_{{$item->id}}' class="hide">
                            <td></td>
                            <td colspan="10">{{ $item->child->merchant_reply_username }}回复：{{ $item->child->content}}</td>
                        </tr>
                    @endif
                @endforeach
                </tbody>
            </table>
            {{ $comment->appends([ 'shop_id' => $shopId])->links() }}

        </div>
        <div class="modal fade loading custom-hide" style="width: 100%;text-align: center" id="hideForm" tabindex="-1"
             role="dialog" aria-labelledby="hideFormLibel" aria-hidden="true" data-backdrop="static"
             data-keyboard="false">
            <div class="modal-dialog">
                <div class="content invoice" style="position: relative; width: 60%; margin: auto">
                    <span id="closeHideForm" class="span-X"><i class="fa fa-close"></i></span>
                    <div class="row" id="image-content">
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade loading custom-hide" id="hideFormSystem" tabindex="-1" role="dialog"
             aria-labelledby="hideFormLibelSystem" aria-hidden="true" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="content invoice" style="text-align: left">
                    <form class='form' action="" method="POST">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
                        <div class="form-group">
                            <label for="level">回复内容：</label>
                            <textarea class="form-control" required="required" name="system_reply" type="text" value="" id="system_reply" rows="8" style="resize:none;"></textarea>
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn btn-success form-control">提交</button>
                            <br/>
                            <br/>
                            <button type="button" class="btn" id="closeHideFormSystem">关闭</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>


        <div class="modal fade loading custom-hide" id="merchantReplySystem" tabindex="-1" role="dialog"
             aria-labelledby="merchantReplyLibelSystem" aria-hidden="true" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="content invoice" style="text-align: left">
                    <form class='form' action="" method="POST">
                        <input type="hidden" name="pid" id="pid">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
                        <div class="form-group">
                            <label for="level">回复内容：</label>
                            <input class="form-control" required="required" name="content" type="text" value=""
                                   id="content">
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn btn-success form-control">提交</button>
                            <br/>
                            <br/>
                            <button type="button" class="btn" id="closeMerchantReplySystem">关闭</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection
@push('stylesheets')
    <style>
        .span-X {
            position: absolute;
            border-radius: 50px;
            top: 10px;
            right: 10px;
            padding: 5px;
            line-height: 0;
            background-color: rgba(190, 190, 190, 0.50);
        }
    </style>
@endpush
@push('scripts')
    <script>
        $('.showHideForm').on('click', function () {
            var k = $(this).attr('data-image').split(";");
            node = "";
            for (index in k) {
                node += "<div style= \"float:left;width: 200px;margin: 10px;\">\n" +
                    "       <img src=\"" + k[index] + "\" width='100%'>\n" +
                    "   </div>";
            }
            $('#image-content').html(node);
            $("#hideForm").modal('show');
        });
        $('#closeHideForm').on('click', function () {
            $("#hideForm").modal('hide');
        });

        $('.examine').on('click', function () {
            $("#hideFormSystem form").attr('action', $(this).attr('data-url'));
            $("#system_reply").val($(this).attr('data-system-reply'))
            $("#hideFormSystem").modal('show');
        });
        $('#closeHideFormSystem').on('click', function () {
            $("#hideFormSystem").modal('hide');
        });


        $('.merchantReply').on('click', function () {
            $("#merchantReplySystem form").attr('action', $(this).attr('data-url'));
            $("#pid").val($(this).attr('data-pid'))
            $("#merchantReplySystem").modal('show');
        });
        $('#closeMerchantReplySystem').on('click', function () {
            $("#merchantReplySystem").modal('hide');
        });
        function viewComment(obj, id){
            if ($(obj).find('i').attr('class') == 'fa fa-angle-down') {
                $(obj).find('i').removeClass('fa fa-angle-down')
                $(obj).find('i').addClass('fa fa-angle-up')
                $('#reply_comment_'+id).removeClass('hide')
            }else{
                $(obj).find('i').removeClass('fa fa-angle-up')
                $(obj).find('i').addClass('fa fa-angle-down')
                $('#reply_comment_'+id).addClass('hide')
            }
        }
    </script>
@endpush
